import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# 中文字体支持
plt.rcParams['font.sans-serif'] = ['STHeiti', 'PingFang SC', 'Heiti TC', 'Microsoft YaHei', 'SimHei', 'Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False

# 年份
years = ["2025", "2030", "2035", "2040", "2045", "2050"]

# 数据
data = [
    ["随到随充", "基准碳约束", 4854.603, 5459.877, 6452.654, 7996.223, 9238.281, 11278.298],
    ["随到随充", "严格碳约束", 4964.951, 5479.581, 6505.837, 8228.103, 9500.905, 11726.516],
    ["有序充电", "基准碳约束", 4829.178, 5359.927, 6229.843, 7625.665, 8714.121, 10601.028],
    ["有序充电", "严格碳约束", 4937.645, 5370.866, 6246.305, 7803.443, 8892.974, 10889.595],
    ["车网互动", "基准碳约束", 4759.170, 5258.473, 6136.425, 7529.550, 8676.871, 10367.661],
    ["车网互动", "严格碳约束", 4828.731, 5259.942, 6150.426, 7656.857, 8787.043, 10526.187]
]

# 创建 DataFrame
columns = ["模式", "场景"] + years
df = pd.DataFrame(data, columns=columns)

# 模式列表
modes = ["随到随充", "有序充电", "车网互动"]

# 子图
fig, axes = plt.subplots(1, 3, figsize=(11, 3.5))

# 绘图
for ax, mode, suffix in zip(axes, modes, ["-UC", "-V1G", "-V2G"]):
    subset = df[df["模式"] == mode]
    baseline = subset[subset["场景"] == "基准碳约束"][years].values.flatten() / 10
    compare = subset[subset["场景"] == "严格碳约束"][years].values.flatten() / 10

    ax.scatter(years, baseline, marker='^', label=f"BAU-LOW{suffix}", color="black")
    ax.scatter(years, compare, marker='x', label=f"SC-LOW{suffix}", color="red")

    ax.set_xlabel("Year")
    ax.set_ylabel("Total Social Cost (100M USD)")
    ax.legend()
    
    # 设置合理的 y 轴范围
    ax.set_ylim(400, 1300)
    ax.set_yticks(np.arange(400, 1400, 200))

plt.tight_layout()
plt.savefig("8.jpg", dpi=400)